import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;


import javax.swing.BoxLayout;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
import java.util.ListIterator;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import java.util.Date;

import calendar_ex.*;
import calendar_ex.Appointment.Recurrence;
import javax.swing.Box;
import javax.swing.Box.Filler;
import javax.swing.table.DefaultTableModel;

import panels.Inner;
import panels.SwipeButtons;

import utils.imageButton;
import views.*;
import functions.*;

//import calendar_ex.*;
//import teamcalendar.*;


public class NewCalendar extends JFrame implements ActionListener, WindowListener{
	
//	CalendarEx cal;
	int screenWidth = 250;
	int screenHeight = 320;
	int screenSizeMult = 2;
	
	JPanel cards;
	
	
	public void createAndShowGUI(){
		setMinimumSize(new Dimension(screenWidth*screenSizeMult, screenHeight*screenSizeMult));
		setVisible(true);
		setTitle("Mob Calendar - Version 2");
		
		
		ControlActionListenter calistener = new ControlActionListenter();
		
		/* Will contain all views: day, week, month */
		JPanel topPane = new JPanel();
		
		/* Will contain all functions: options, agenda, add appointment */
		JPanel bottomPane = new JPanel();
		
		imageButton dayViewBttn = new imageButton("img/day.jpg",44,44);
		dayViewBttn.setActionCommand("DAY_VIEW");
		dayViewBttn.addActionListener(calistener);
		topPane.add(dayViewBttn, "DAY_VIEW");
		
		imageButton weekViewBttn = new imageButton("img/week.jpg",44,44);
		weekViewBttn.setActionCommand("WEEK_VIEW");
		weekViewBttn.addActionListener(calistener);
		topPane.add(weekViewBttn, "WEEK_VIEW");
		
		imageButton monthViewBttn = new imageButton("img/month.jpg",44,44);
		monthViewBttn.setActionCommand("MONTH_VIEW");
		monthViewBttn.addActionListener(calistener);
		topPane.add(monthViewBttn, "MONTH_VIEW");
		
		//imageButton optionsBttn = new imageButton("img/up_arrow_black.gif",44,44);
		Button optionsBttn = new Button("Options");
		optionsBttn.setActionCommand("OPTIONS");
		optionsBttn.addActionListener(calistener);
		bottomPane.add(optionsBttn, "OPTIONS");
		
		Button agendaBttn = new Button("Agenda");
		agendaBttn.setSize(44,44);
		agendaBttn.setActionCommand("AGENDA");
		agendaBttn.addActionListener(calistener);
		bottomPane.add(agendaBttn, "AGENDA");
		
		//imageButton addApptBttn = new imageButton("img/combo_plus_sign2.png",44,44);
		Button addApptBttn = new Button("Add Appointment");
		addApptBttn.setActionCommand("ADD_APPT");
		addApptBttn.addActionListener(calistener);
		bottomPane.add(addApptBttn, "ADD_APPT");
		
		
		/* Create all views */
		cards = new JPanel(new CardLayout());
		cards.add(new DayView(), "DAY_VIEW");
		cards.add(new WeekView(), "WEEK_VIEW");
		cards.add(new MonthView(), "MONTH_VIEW");
		cards.add(new AddAppointment(), "ADD_APPT");
		cards.add(new ViewOptions(), "OPTIONS");
		
		
		topPane.setVisible(true);
		//topPane.setBackground(new Color(93,138, 168));
		
		bottomPane.setVisible(true);
		//bottomPane.setBackground(new Color(93,138, 168));
		
		
		
		/*Add top and bottom panes*/
		getContentPane().add(topPane, BorderLayout.PAGE_START);
		getContentPane().add(cards, BorderLayout.CENTER);
		getContentPane().add(bottomPane, BorderLayout.PAGE_END);
	}
	
	class ControlActionListenter implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            CardLayout cl = (CardLayout) (cards.getLayout());
            String cmd = e.getActionCommand();
            if (cmd.equals("DAY_VIEW")) {
                cl.show(cards, "DAY_VIEW");
            }
            else if (cmd.equals("WEEK_VIEW")){
            	cl.show(cards, "WEEK_VIEW");
            }
            else if (cmd.equals("MONTH_VIEW")){
            	cl.show(cards, "MONTH_VIEW");
            }
            else if (cmd.equals("ADD_APPT")){
            	cl.show(cards, "ADD_APPT");
            }
            else if (cmd.equals("OPTIONS")){
            	cl.show(cards, "OPTIONS");
            }
            else if (cmd.equals("AGENDA")){
            	cl.show(cards, "AGENDA");
            }
            
        }
    }
    
	
	public static void main(String[] args){
		
		
        
		javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
            	NewCalendar cal = new NewCalendar();
                cal.createAndShowGUI();
            }
        });
	}
	
	public class MainPanel extends JPanel{
		public MainPanel(){
			
		}
	}

	@Override
	public void windowOpened(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowClosing(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowClosed(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowIconified(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowDeiconified(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowActivated(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void windowDeactivated(WindowEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		
	}

	
	
}